package com.cnfangmao.masterdata.service.impl;

import java.util.List;

import com.cnfangmao.masterdata.model.AccountRole;
import com.cnfangmao.masterdata.dao.AccountRoleDao;
import com.cnfangmao.masterdata.dto.AccountRoleSearchDto;
import com.cnfangmao.masterdata.dto.GeneralSearchDto;
import com.cnfangmao.masterdata.service.AccountRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 账号角色关联表 服务实现类
 * </p>
 *
 * @author chenxd
 * @since 2020-04-17
 */
@Service
public class AccountRoleServiceImpl extends ServiceImpl<AccountRoleDao, AccountRole> implements AccountRoleService {

	@Autowired
	private AccountRoleDao dao;
	
	@Override
	public AccountRole findByUserIdAndRoleId(String userId, String roleId) {
		AccountRole accountRole =null;
		QueryWrapper<AccountRole> queryWrapper =new QueryWrapper<AccountRole>();
		queryWrapper.eq("user_id", userId);
		queryWrapper.eq("role_id", roleId);
		accountRole=dao.selectOne(queryWrapper);
		return accountRole;
	}

	@Override
	public IPage<AccountRole> queryListAccountRole(GeneralSearchDto<AccountRoleSearchDto> dto) {
		IPage<AccountRole> page = new Page<AccountRole>(dto.getPageNo(), dto.getPageSize());
		IPage<AccountRole> listPage =dao.queryListAccountRole(page,dto.getConditions().getUserName(), dto.getConditions().getRoleName());
		return listPage;
	}

	@Override
	public List<AccountRole> findListByUserId(String userId) {
		QueryWrapper<AccountRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        List<AccountRole> accountRoles = dao.selectList(queryWrapper);
		return accountRoles;
	}

}
